﻿Imports System.Data.SqlClient

Public Class frmGratiNuevo
    Dim Bitacora As New clsActividad
    Dim existenCargos As Boolean
    Private Sub frmGratiNuevo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CheckBox1.Checked = False

        Me.dgCargos.Rows.Clear()
        existenCargos = False

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Gratificaciones " & _
        " WHERE notificado='No' order by fecha"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim nombre As String
        Do While rdBuscar.Read()
            existenCargos = True
            nombre = BuscarStrDatoCitra("Empleados", "NombreCompleto", "IdEmpleado=" & rdBuscar("IdEmpleado"))
            Me.dgCargos.Rows.Add(nombre, rdBuscar("tipo"), rdBuscar("monto"), rdBuscar("tipohora"), rdBuscar("usuario"), rdBuscar("motivo"))
        Loop

        If existenCargos = False Then
            Me.Close()

        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub btnAbrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbrir.Click
        ToExcel(Me.dgCargos, "Relación de nuevos pagos al " & Now())
    End Sub

    Private Sub RadButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton2.Click
        If Me.CheckBox1.Checked = True Then
            Call SetSqlCitra("Update Gratificaciones set notificado='Si' where notificado='No'")
            Bitacora.RegistraActividad("Revisó las notificaciones de nuevas gratificaciones")
            Me.Close()
        Else
            Me.Close()
        End If
    End Sub
End Class